<template>
	<view class="maintenance-page">
		<view class="top-box">
			<view class="input-search">
				<input type="text" placeholder="搜索场地名称" v-model="keywords" />
				<image src="../../static/images/home/切片@2x.png" @click="getGroundMap"></image>
			</view>
			<!-- 	<view class="select-box">
				<view class="select-flex">
					<uni-data-select v-model="selected" :localdata="selectList"
						@change="onChange"></uni-data-select>
				</view>
				<view class="select-flex">
					<uni-data-select v-model="selectedStatus" :localdata="selectListStatus"
						@change="onChangeStatus"></uni-data-select>
				</view>
			</view> -->
		</view>
		<view class="ground-list">
			<div class="ground-item" v-for="(item,index) in groundMapList" :key="index" @click="navigatorPage(item)">
				<view class="item-top">
					<view class="ground-name">{{item.name}}</view>
					<view class="distance" @click.stop="navigatorMap(item)">
						<image src="../../static/images/maintenance/map.png" class="image"></image>
						<view>{{item.distance}}km</view>
					</view>
				</view>
				<view class="item-center">{{item.city}} {{item.address}}</view>
				<view class="item-bottom">
					<view class="phone blue" @click.stop="makePhoneCall(item.child_mobile)">
						<image src="../../static/images/maintenance/phone.png" class="image"></image>
						{{item.child_mobile}}
					</view>
					<view class="device">
						<image src="../../static/images/maintenance/equip.png" class="image"></image>
						<view> 正常: <text class="blue">{{item.health_devices}}</text>/{{item.total_devices}}
						</view>
					</view>
				</view>
			</div>
		</view>
	</view>
</template>

<script>
	import api from '@/api/index.js';
	export default {
		data() {
			return {
				lat: '',
				lng: '',
				keywords:'',
				groundMapList: []
			}
		},
		onLoad() {
			let that = this
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					that.lat = res.latitude
					that.lng = res.longitude
					that.getGroundMap()
					console.log('当前位置的经度：' + res.longitude);
					console.log('当前位置的纬度：' + res.latitude);
				}
			});

		},
		methods: {
			navigatorMap(item) {
				window.location.href =
					`https://apis.map.qq.com/tools/routeplan/eword=${item.name}&epointx=${item.lng}&epointy=${item.lat}?referer=myapp&key=34GBZ-ZG66D-KV54R-P3DBA-L5F6O-QQFOT`
			},
			makePhoneCall(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				})
			},
			navigatorPage(item) {
				uni.navigateTo({
					url: '/pages/maintenance/deviceList?id='+item.id
				})
			},
			getGroundMap() {
				api.getGroundMap({
					lat: this.lat,
					lng: this.lng,
					keywords:this.keywords
				}).then(res => {
					if (res.code == 1) {
						this.groundMapList = res.data.list
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.top-box {
		padding: 20rpx;
		background: #ffffff;
		.input-search {
			position: relative;
			uni-input {
				background: #f8f8f8;
				box-shadow: 0rpx 12rpx 116rpx 0rpx rgba(196, 203, 214, 0.1);
				border-radius: 24rpx;
				font-weight: 400;
				font-size: 28rpx;
				color: #7d8592;
				padding: 24rpx 40rpx;
				font-style: normal;
			}

			uni-image {
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				right: 24rpx;
				top: 20rpx;
			}
		}

		.select-box {
			display: flex;
			margin: 30rpx 0 20rpx;

			.select-flex {
				flex: 1;
				margin-right: 40rpx;

				&:last-child {
					margin-right: 0;
				}
			}
		}
	}
	.ground-list{
		margin: 20rpx;
		.ground-item{
			border-radius: 10rpx;
			padding: 20rpx;
			background-color: #ffffff;
			margin-bottom: 20rpx;
			.image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 10rpx;
			}
			
			.item-top{
				display: flex;
				justify-content: space-between;
				.ground-name{
					font-weight: bold;
					font-size: 30rpx;
				}
				
				.distance {
					display: flex;
					align-items: center;
				}
			}
			.item-center{
				margin: 10rpx 0;
				color: #959595;
			}
			.item-bottom{
				display: flex;
				justify-content: space-between;
				.blue{
					color: #5799ec;
				}
				.phone {
					display: flex;
					align-items: center;
				}
				
				.device {
					font-size: 24rpx;
					display: flex;
					align-items: center;
				}
			}
		}
	}

</style>